package com.app.couponsharelife.ui.view
import android.content.Context
import android.graphics.drawable.Drawable
import android.text.Html
import android.graphics.drawable.BitmapDrawable
import android.graphics.Bitmap
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.Glide
import android.graphics.drawable.LevelListDrawable
import android.widget.TextView
import com.bumptech.glide.request.transition.Transition


/**
 *Created by xct on 2019/5/9
 *Description:
 */
class MImageGetter(val context: Context,val textview:TextView): Html.ImageGetter {
    override fun getDrawable(source: String?): Drawable {
        val drawable = LevelListDrawable()
        Glide.with(context).asBitmap().load(source).into(object : SimpleTarget<Bitmap>() {
            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                if (resource != null) {
                    val bitmapDrawable = BitmapDrawable(resource)
                    drawable.addLevel(1, 1, bitmapDrawable)
                    drawable.setBounds(0, 0, 50, 50)
                    drawable.level = 1
                    textview.invalidate()
                    textview.text = textview.text
                }
            }

        })
        return drawable
    }
}